package com.client.mikocompose.ui.modules.home

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.client.mikocompose.ui.DataGen
import com.linx.common.base.BaseViewModel
import kotlinx.coroutines.delay

/**
 * 首页
 */
class HomeViewModel : BaseViewModel() {

//    //首页列表
//    val homeListData: Flow<PagingData<ArticleListData>>
//        get() = _homeListData
//
//    private val _homeListData = Pager(PagingConfig(pageSize = 20)) {
//        CommonPagingSource { nextPage: Int ->
//            HomeRepo.getHomeList(nextPage)
//        }
//    }.flow.cachedIn(viewModelScope)


    //轮播图的数据
    private val _homeListData = MutableLiveData<List<HomeModel>>()
    val homeListData: LiveData<List<HomeModel>>
        get() = _homeListData

    /**
     * 获取首页轮播图
     */
    fun getBannerData() = serverAwait {
        delay(1500)
        val list = mutableListOf<HomeModel>()
        list.add(HomeModel(style = HomeStyle.ONE_GAME, data = DataGen.genData(DataGen.fk())))
        list.add(
            HomeModel(
                style = HomeStyle.TWO_GAME,
                data =
                DataGen.genTwoGame(
                    mutableListOf(
                        DataGen.genData(DataGen.fxq()),
                        DataGen.genData(DataGen.nhwc())
                    )
                )
            )
        )
        list.add(
            HomeModel(
                style = HomeStyle.TWO_GAME,
                data =
                DataGen.genTwoGame(
                    mutableListOf(
                        DataGen.genData(DataGen.wzq()),
                        DataGen.genData(DataGen.bwfw())
                    )
                )
            )
        )
        list.add(
            HomeModel(
                style = HomeStyle.BANNER,
                data = DataGen.genBanner()
            )
        )
        list.add(
            HomeModel(
                style = HomeStyle.TITLE,
                data = DataGen.genTitle()
            )
        )
        DataGen.genRank().forEach {
            list.add(
                HomeModel(
                    style = HomeStyle.RANK,
                    data = it
                )
            )
        }
        _homeListData.postValue(list)
    }

}